class Solution {
public:
    vector<vector<int>> matrixReshape(vector<vector<int>>& nums, int r, int c) {
        int row=nums.size();
        int col=nums[0].size();
        if(col*row!=r*c){
            return nums;
        }
        if(col==c){
            return nums;
        }
        vector<int> tmp;
        vector<vector<int>> res(r,vector<int>(c));
        //cout<<res.size()<<" "<<res[0].size()<<endl;
        for(int i=0;i<nums.size();i++){
            for(int j=0;j<nums[0].size();j++){
                tmp.push_back(nums[i][j]);
            }
        }
        for(int i=0;i<tmp.size();i++){
            res[i/c][i%c]=tmp[i];
        }
        return res;
    }
};